package org.brisling.medical.queryService;

import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.exception.DangerousOperatorException;
import org.brisling.common.util.DateUtil;
import org.brisling.medical.domain.OutpatientItem;
import org.brisling.sysman.queryService.QueryDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * <p>Title: QueryOutpatientItemService</p>
 * <p>Description: 门诊医嘱项目查询service</p>
 * <p>Company: tongking</p>
 * @author peter fan
 * @since 1.0
 * @version 1.0
 * @date 2016年7月20日 下午10:10:55
 */
@RestController
@RequestMapping("/medicalOutpatientItem/query")
public class QueryOutpatientItemService extends AbstractBaseQueryService<OutpatientItem>{
	
	
	@Autowired
	private QueryDictionaryService dicService;
	
	public QueryOutpatientItemService(){
		this.moduleName = ConstSysParam.MODULE_INPATIENT_ITEM;
		this.subSystem = ConstSysParam.SUBSYSTEM_MEDICAL;
		this.tableName = ConstSysParam.VIEW_PREFIX +this.getTableName(OutpatientItem.class);
		this.clazz = OutpatientItem.class;
		
		typeMap = this.getTypeMap(clazz);
		
		orderMap.put("operateat","desc");
		
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	
	
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
	
	@RequestMapping("/getListDomain.action")
	public ListDomain<OutpatientItem> getListDomain(@RequestBody(required=false) String body){	
		
		return super.getListDomainByConditionAndOrder(body, typeMap, orderMap,false);
		
	}
	

	@RequestMapping("/getListDomainDrug.action")
	public ListDomain<OutpatientItem> getListDomainDrug(@RequestBody(required = false) String body){
		String sql = dicService.getSqlByBizcode("medical_outpatient_item_full");
		Map<String,Object> map = getBodyParam(body);
		return super.getListDomainByConditionAndOrder(sql, map, typeMap, orderMap,false);
//		super.getAllList(page, row, condition, sort)
//		return new ListDomain<>();
	}
	
	@RequestMapping("/getList.action")
	public ListDomain<OutpatientItem> getList(@RequestBody(required=false) String body){		
		
		return super.getListDomainByConditionAndOrder(body, typeMap, orderMap,false);
	}
	
	/**
	 * 根据用户id查找用户信息
	 * @param id	用户id
	 * @return 用户信息记录 
	 */
	@RequestMapping("/getOne.action")
	public OutpatientItem getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public OutpatientItem getOneByIdentify(@RequestParam(value="identify",required=false) String identify){	
		return super.getOneByIdentify(identify);
	}
	
	//OutpatientItem
	/**
	 * 医嘱异常数据
	 * @return
	 */	

	public List<OutpatientItem> getOutpatientItemAbnormal(){		
				
		String sql = dicService.getSqlByBizcode("medical_outPatient_item");		
		//sql = new String("select * from medical_anti_dose");
		sql = String.format(sql, DateUtil.getYestodayMonthDay()[2]);
		try {
			return super.getClassedAllList(sql, OutpatientItem.class);
		} catch (DangerousOperatorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 	
		return null;
	}
}
